package chapter4;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import chapter3.Attr;

/**
 * another approach is define a class
 * @author wei
 * @see Attributed
 */
public class AttributedC implements Attributed, Iterable<Attr> {
    
    protected Map<String, Attr> attrTable = new HashMap<String, Attr>();

    public void add(Attr newAttr) {
        attrTable.put(newAttr.getName(), newAttr);
    }

    public Attr find(String attrName) {
        return attrTable.get(attrName);
    }

    public Attr remove(String attrName) {
        return attrTable.remove(attrName);
    }

    public Iterator<Attr> attrs() {
        return attrTable.values().iterator();
    }

    public Iterator<Attr> iterator() {
        return attrs();
    }

}
